Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
@reach/portal
Advanced tools
@reach/portal is a React component that allows you to render children into a DOM node that exists outside the DOM hierarchy of the parent component. This is useful for creating modals, tooltips, and other UI elements that need to visually break out of their container.
Basic Portal Usage
This example demonstrates the basic usage of the @reach/portal package. The `Portal` component is used to render a div outside of the parent DOM hierarchy, which can be useful for creating modals or tooltips.
import React from 'react';
import { Portal } from '@reach/portal';
function App() {
return (
<div>
<h1>My App</h1>
<Portal>
<div style={{ position: 'absolute', top: 0, left: 0, background: 'white', border: '1px solid black' }}>
This is rendered in a portal!
</div>
</Portal>
</div>
);
}
export default App;
Nested Portals
This example shows how you can nest portals within each other. The nested `Portal` component renders its children outside of the parent DOM hierarchy, allowing for complex UI structures.
import React from 'react';
import { Portal } from '@reach/portal';
function App() {
return (
<div>
<h1>My App</h1>
<Portal>
<div style={{ position: 'absolute', top: 0, left: 0, background: 'white', border: '1px solid black' }}>
This is rendered in a portal!
<Portal>
<div style={{ position: 'absolute', top: 20, left: 20, background: 'lightgray', border: '1px solid black' }}>
This is a nested portal!
</div>
</Portal>
</div>
</Portal>
</div>
);
}
export default App;
The `react-dom` package provides the `createPortal` method, which allows you to render children into a DOM node that exists outside the DOM hierarchy of the parent component. It is a core part of React and offers similar functionality to @reach/portal but is more integrated into the React ecosystem.
The `react-portal` package is another popular library for creating portals in React. It offers a simple API and additional features like event handling and portal management. It is more feature-rich compared to @reach/portal but may be overkill for simple use cases.
The `react-reverse-portal` package allows you to create portals that can be moved around the DOM dynamically. It provides more advanced features for managing portal content and is useful for complex applications that require dynamic portal management. It offers more flexibility compared to @reach/portal.
FAQs
Declarative portals for React
The npm package @reach/portal receives a total of 389,041 weekly downloads. As such, @reach/portal popularity was classified as popular.
We found that @reach/portal demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.